﻿#ifndef TGRAPHICSVIEWREFACTOR_H
#define TGRAPHICSVIEWREFACTOR_H

#include <QGraphicsView>

class ElementGraphicsView : public QGraphicsView
{
    Q_OBJECT
public:
    ElementGraphicsView(QWidget *parent = nullptr);
    ElementGraphicsView(QGraphicsScene *scene, QWidget *parent = nullptr);

    inline qreal multiple()const{return mMultiple;}
signals:
    void zoom(qreal);
public:
    inline void setHorizonRuler(bool b){
        mbHorizonRuler=b;
        QGraphicsView::update();
    }
    inline bool isHorizonRuler()const{
        return mbHorizonRuler;
    }
    inline void setVerticalRuler(bool b){
        mbVerticalRuler=b;
        QGraphicsView::update();
    }
    inline bool isVerticalRuler()const{
        return mbVerticalRuler;
    }
    inline void setGridLine(bool b){
        mbGridLine = b;
        QGraphicsView::update();
    }
    inline bool isGridLine()const{
        return mbGridLine;
    }
    void scaleView(qreal scaleFactor);

public slots:

protected:
    void paintEvent(QPaintEvent *event) override;
    void drawBackground(QPainter *painter, const QRectF &rect) override;
#if QT_CONFIG(wheelevent)
    void wheelEvent(QWheelEvent *event) override;
#endif

private:
    void drawHorizonRuler(QPainter &painter);
    void drawVerticalRuler(QPainter &painter);
    void drawRuleCross(QPainter &painter);
    void drawHorGridLine(QPainter &painter);
    void drawVerGridLine(QPainter &painter);
    void setSliperStyle();
private:
    bool mbHorizonRuler = true;
    bool mbVerticalRuler = true;
    bool mbGridLine = true;
    qreal mMultiple = 1.;
    static const int miStep = 20;// 画网格线的间距，坐标系是view坐标
};

#endif // TGRAPHICSVIEWREFACTOR_H
